package com.export.thread;

import com.alibaba.fastjson.JSONObject;
import com.export.bean.model.EmailModel;
import com.export.bean.model.StateModel;
import com.export.config.Contansts;
import com.export.service.Impl.DeviceKvHistoryRepository_UNITED;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.PostConstruct;

/**
 * Created by Studio on 2017/5/11.
 * 测试用
 */
@Component
public class TestThread extends Thread{

    private static final Logger logger = LoggerFactory.getLogger(ActionThread.class);

    @Autowired
    private DeviceKvHistoryRepository_UNITED deviceKvHistoryRepositoryXSD;
    @Autowired
    private JedisPool jedisPool;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    private static TestThread testThread;
    private StateModel stateModel;

    private Jedis redis; //= new Jedis(Contansts.redisHost, Contansts.redisPort,Contansts.redisTimeOut);

    public TestThread() {
        stateModel = new StateModel();
    }



    @PostConstruct     //关键二   通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
    public void init() {
        testThread = this;
        testThread.deviceKvHistoryRepositoryXSD = this.deviceKvHistoryRepositoryXSD;
        testThread.jedisPool = this.jedisPool;
        testThread.jdbcTemplate = this.jdbcTemplate;
    }

//    @Override
//    public void run() {
//        String QueryString = "INSERT INTO history_05_24_14 ( created, device_id, property, `value` ) VALUES (" +
//                "'1495607297'," +
//                "'bab5c274384b404fa941ac52b306e790/867967023379227'," +
//                "'crn_v_fltcode'," +
//                "'1'" +
//                ")";
//
//        for(int i = 0;i<100000;i++){
//            testThread.jdbcTemplate.execute(QueryString);
//            logger.info(i+"");
//        }
//        logger.info("success");
//    }

}
